#ifndef JOYSTICK_H
#define JOYSTICK_H
#include <Arduino.h>
#include <math.h>

class joystick
{
    private:
        char X;
        char Y;
    public:
        joystick(char x, char y) : X(x), Y(y) {}
        void read(char &x, char &y) {
            x = (analogRead(X)-511.5)/4.0;
            y = (analogRead(Y)-511.5)/4.0;
        }
        void coord(float &x, float &y) {
            x = (analogRead(X)-511.5)/511.5;
            y = (511.5-analogRead(Y))/511.5;
        }
        void polar(float &r, float &theta) {
            float x, y;
            coord(x, y);
            r = sqrt(x*x+y*y);
            theta = atan2(y, x);
        }
};
#endif
